package com.hung.thread.volatile_test;

public class VolatileTestDemo
{
    private static volatile int rac = 0;
    
    private static final int threadCnt = 20;
    
    public static void increase()
    {
        rac++;
    }
    
    public static void main(String[] args)
    {
        Thread[] thread = new Thread[threadCnt];
        for(int i=0; i<threadCnt; i++)
        {
            thread[i] = new Thread(new Runnable()
            {

                @Override
                public void run()
                {
                    for(int j=0; j < 10000; j++)
                    {
                        increase();
                    }
                    
              }});
            thread[i].start();
        }
        
        while(Thread.activeCount() > 1)
        {
            Thread.yield();
        }
        
        System.out.println(rac);
    }
}